﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace HotelManageSystem.Models
{
    /// <summary>
    /// Class Name:     ContractModel
    /// Author:         Wangzx
    /// Creation Date:  2012-3-16
    /// Description:    员工的合同
    /// QA:             
    /// -----------------------------------------
    /// </summary>
    public class ContractModel
    {
        [Display(Name = "员工编号")]
        public int ID { get; set; }
        [Display(Name = "员工姓名")]
        public string Name { get; set; }
        [Display(Name = "性别")]
        public string Sex { get; set; }
        [Display(Name = "员工状态")]
        public string EmployeeStatus { get; set; }

        [Display(Name = "合同类型")]
        [StringLength(6, ErrorMessage = "合同类型不能超过6个字符")]
        public string ContractType { get; set; }

        [Display(Name = "合同起日")]
        [DataType(DataType.Date, ErrorMessage = "必须输入时间类型")]
        public DateTime BeginContractDate { get; set; }

        [Display(Name = "合同止日")]
        [DataType(DataType.Date, ErrorMessage = "必须输入时间类型")]
        public DateTime EndContractDate { get; set; }

        [Display(Name = "备注")]
        [StringLength(60, ErrorMessage = "备注不能超过60个字符")]
        public string ContractRemark { get; set; }

        [Display(Name = "距合同到期天数")]
        public string IsEnd
        {
            get
            {
                //如果合同签订日期为默认日期"1900/1/1",则表明还未签订
                if (BeginContractDate.Year == 1900)
                {
                    return "未签订合同";
                }
                if (EmployeeStatus == "离职状态")
                {
                    return "已离职";
                }
                bool b = DateTime.Now >= EndContractDate;
                if (b)
                {
                    return "合同已过期";
                }
                else
                {
                    return GetDays();
                }
            }
        }

        private string GetDays()
        {
            TimeSpan t1 = new TimeSpan(DateTime.Now.Ticks);
            TimeSpan t2 = new TimeSpan(EndContractDate.Ticks);
            TimeSpan ts = t2.Subtract(t1).Duration();
            return ts.Days.ToString();
        }
    }
}